package com.gdth.bank.widget;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.gdth.bank.R;
import com.gdth.bank.adapter.JtcyCpzlListAdapter;
import com.gdth.bank.bean.BfjlCpxqItem;
import com.gdth.bank.utils.AppUtil;
import com.gdth.database.bean.TAppBfrjCpxq;
import com.gdth.model.Item;
import com.gdth.widget.dialog.BaseDialog;

public class DialogConfigSpinner extends BaseDialog {
	ListView mListView;
	private View.OnClickListener mOnClickListener;
	private JtcyCpzlListAdapter  adapter;
	private List<BfjlCpxqItem>   mBfjlCpxqItemList;
	private List<Item> items;
	public DialogConfigSpinner(Context context, String title, boolean dismiss) {
		super(context, R.style.dialog_theme);
		
		this.title = title;
		this.dismiss = dismiss;
		
		initView();
	}
	
	public DialogConfigSpinner(Context context, String title, boolean dismiss, View.OnClickListener mOnClickListener) {
		super(context, R.style.dialog_theme);
		
		this.title = title;
		this.dismiss = dismiss;
		this.mOnClickListener = mOnClickListener;
		
//	   
		
		init();
		initView();
	}
	
	protected void init(){
		mBfjlCpxqItemList = new ArrayList<BfjlCpxqItem>();
		items = AppUtil.getCanshuByType(context, AppUtil.SHARE_DATA_SBZT);
		for(int i=0;i<items.size();i++){
			BfjlCpxqItem  mBfjlCpxqItem = new BfjlCpxqItem();
			mBfjlCpxqItem.setKey(items.get(i).getKey());
			mBfjlCpxqItem.setValue(items.get(i).getValue());
			mBfjlCpxqItem.setCheck(false);
			mBfjlCpxqItemList.add(mBfjlCpxqItem);
		}
		
		
//		BfjlCpxqItem mBfjlCpxqItem= new BfjlCpxqItem();
//		mBfjlCpxqItem.setKey("0");
//		mBfjlCpxqItem.setValue("申请登记");
//		mBfjlCpxqItemList.add(mBfjlCpxqItem);
//		BfjlCpxqItem mBfjlCpxqItem2= new BfjlCpxqItem();
//		mBfjlCpxqItem2.setKey("1");
//		mBfjlCpxqItem2.setValue("已成交");
//		mBfjlCpxqItemList.add(mBfjlCpxqItem2);
		
	
	}
	
	
	protected void initView(){
		super.initView(R.layout.jtcyzc_dialog);
		
		LinearLayout linearlayout = (LinearLayout) findViewById(R.id.dialog_content);
		mListView = (ListView) findViewById(R.id.cjkh_jtxx_cpxq_listview);
		
		if (dismiss)
			linearlayout.setOnClickListener(new dismissOnClickListener());
        
		TextView txt_config = (TextView) findViewById(R.id.dialog_button_ok);
		
		TextView txt_cancle = (TextView) findViewById(R.id.dialog_button_cancel);
		TextView txt_title = (TextView) findViewById(R.id.dialog_title);
		txt_title.setText(title);
		txt_cancle.setOnClickListener(new dismissOnClickListener());
		
		if (this.mOnClickListener != null)
			txt_config.setOnClickListener(this.mOnClickListener);
		else 
			txt_config.setOnClickListener(new configOnClickListener());
		adapter = new JtcyCpzlListAdapter(context, mBfjlCpxqItemList);
		 mListView.setAdapter(adapter);
		
	}
	
	private class configOnClickListener implements View.OnClickListener{
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			dismiss();
			
			if (configListener != null){
				configListener.OnConfigClickListener();
			}
		}
	}
	
	
	public List<String> getCpZlXx(){
		int  dataSize=mBfjlCpxqItemList.size();
		List<TAppBfrjCpxq> mTAppBfrjCpxqData = new ArrayList<TAppBfrjCpxq>();
		String lx="";
		List<String>  list = new ArrayList<String>();
 		
		for(int i=0;i<dataSize;i++){
			if(mBfjlCpxqItemList.get(i).isCheck()){
				lx =mBfjlCpxqItemList.get(i).getKey();
				list.add(lx);
			}
				
		}
		
		return  list;
	}
	

	public int getCountCpZlXx(){
		int  dataSize=mBfjlCpxqItemList.size();
		List<TAppBfrjCpxq> mTAppBfrjCpxqData = new ArrayList<TAppBfrjCpxq>();
		 int j=0;
		List<String>  list = new ArrayList<String>();
 		
		for(int i=0;i<dataSize;i++){
			if(mBfjlCpxqItemList.get(i).isCheck()){
				j++;
			}
				
		}
		
		return  j;
	}

	public void getLx(List<String> str){
		mBfjlCpxqItemList.clear();
		items = AppUtil.getCanshuByType(context, AppUtil.SHARE_DATA_SBZT);
		for(int i=0;i<items.size();i++){
			BfjlCpxqItem  mBfjlCpxqItem = new BfjlCpxqItem();
			for(int j=0;j<str.size();j++){
				mBfjlCpxqItem.setKey(items.get(i).getKey());
				mBfjlCpxqItem.setValue(items.get(i).getValue());
				if(items.get(i).getKey().equals(str.get(j))){
					mBfjlCpxqItem.setCheck(true);
				}
			}
//			BfjlCpxqItem  mBfjlCpxqItem = new BfjlCpxqItem();
//			mBfjlCpxqItem.setKey(items.get(i).getKey());
//			mBfjlCpxqItem.setValue(items.get(i).getValue());
//			if(str.equals(items.get(i).getKey())){
//				mBfjlCpxqItem.setCheck(true);
//			}else{
//			mBfjlCpxqItem.setCheck(false);}
			mBfjlCpxqItemList.add(mBfjlCpxqItem);
		}
	}
	
	public static void main(String[] args){
		String[] arr = {"0","1"};
		//System.out.println(arr.toString());
		List<String> str= new ArrayList<String>();
		str.add("1");
		
	}
	
}
